using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    public class ANDControl
    {
        #region Local Variable
        private ANDDataAccess _ANDDAO;
        #endregion Local Variable

        #region Method
        public ANDControl()
        {
            _ANDDAO = new ANDDataAccess();
        }

        public ANDInfo Get(
            String SUN_DB,
            String CATEGORY,
            String SUBCATEGORY
        , ref string sErr)
        {
            return _ANDDAO.Get(
            SUN_DB,
            CATEGORY,
            SUBCATEGORY
            , ref sErr);
        }

        public DataTable GetAll(
            String SUN_DB
        , ref string sErr)
        {
            return _ANDDAO.GetAll(
            SUN_DB
            , ref sErr);
        }

        public Int32 Add(ANDInfo obj, ref string sErr)
        {
            return _ANDDAO.Add(obj, ref sErr);
        }

        public string Update(ANDInfo obj)
        {
            return _ANDDAO.Update(obj);
        }

        public string Delete(
            String SUN_DB,
            String CATEGORY,
            String SUBCATEGORY
        )
        {
            return _ANDDAO.Delete(
            SUN_DB,
            CATEGORY,
            SUBCATEGORY
            );
        }
        public Boolean IsExist(
            String SUN_DB,
            String CATEGORY,
            String SUBCATEGORY
        )
        {
            return _ANDDAO.IsExist(
            SUN_DB,
            CATEGORY,
            SUBCATEGORY
            );
        }

        /*  public string Delete(String arrID)
          {
              string kq = "";
              string[] arrStrID = arrID.Split(',');
              foreach (string strID in arrStrID)
              {
                  if (strID != "")
                  {
                      int ID = Convert.ToInt32(strID);
                      kq += _ANDDAO.Delete(ID);
                  }
              }
              return kq;
          } 
		
          public DataTableCollection Get_Page(ANDInfo obj, string orderBy, int pageIndex, int pageSize,ref String sErr)
          {
              return _ANDDAO.Get_Page(obj, orderBy, pageIndex, pageSize, ref sErr);
          }*/

        public DataTable Search(String columnName, String columnValue, String condition, String tableName, ref String sErr)
        {
            return _ANDDAO.Search(columnName, columnValue, condition, tableName, ref  sErr);
        }
        public DataTable GetCategory(
           String SUN_DB
       , String CATEGORY, ref string sErr)
        {
            return _ANDDAO.GetCategory_AND(SUN_DB, CATEGORY, ref sErr);
        }

        #endregion Method


        public DataTable GetTransferOut(string dtb, string from, string to, ref string sErr)
        {
            return _ANDDAO.GetTransferOut(dtb, from, to, ref sErr);
        }

        internal DataTable ToTransferInStruct()
        {
            DataTable dt = new DataTable("AND");
            dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn("SUN_DB", typeof(String)),
				new DataColumn("LOOKUP", typeof(String)),
				new DataColumn("UPDATED", typeof(String)),
				new DataColumn("CATEGORY", typeof(String)),
				new DataColumn("SUBCATEGORY", typeof(String)),
				new DataColumn("DESCRIPTION", typeof(String)),
				new DataColumn("SHORTDESC", typeof(String)),
				new DataColumn("MASK", typeof(String)),
				new DataColumn("NONVALIDATED", typeof(String)),
				new DataColumn("AMENDABLE", typeof(String))
				});
            return dt;
        }

        public string InsertUpdate(ANDInfo aNDInfo)
        {
            string sErr = "";
            if (IsExist(aNDInfo.SUN_DB, aNDInfo.CATEGORY, aNDInfo.SUBCATEGORY))
                sErr = Update(aNDInfo);
            else
                Add(aNDInfo, ref sErr);
            return sErr;
        }

        public string TransferIn(DataRow row)
        {
            return InsertUpdate(new ANDInfo(row));
        }
    }
}
